-
Notifications
You must be signed in to change notification settings - Fork 62
feat: add ignoreUnknownFields to protobuf JSON parsing #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Junyi-99 <[email protected]>
Co-authored-by: Junyi-99 <[email protected]>
Co-authored-by: Junyi-99 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses a critical issue where the webapp crashes when the backend introduces new protobuf fields. By wrapping all fromJson calls with a utility that sets ignoreUnknownFields: true, the webapp can now gracefully handle responses from newer backend versions, implementing proper forward compatibility.
Key Changes:
- Created a
protobuf-utils.tswrapper that configuresfromJsonto ignore unknown fields - Updated all 12 files that use
fromJsonto import from the new wrapper instead of directly from@bufbuild/protobuf - Added a test/documentation file demonstrating the expected behavior
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
webapp/_webapp/src/libs/protobuf-utils.ts |
New utility wrapper that adds ignoreUnknownFields: true to all protobuf JSON parsing |
webapp/_webapp/src/libs/protobuf-utils.test.ts |
Documentation/manual test file demonstrating the wrapper's behavior with unknown fields |
webapp/_webapp/src/views/prompts/prompt-library-table.tsx |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/views/devtools/index.tsx |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/stores/conversation/handlers/handleStreamError.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/stores/conversation/handlers/converter.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/stores/conversation/conversation-store.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/query/utils.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/query/api.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/libs/apiclient.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/hooks/useSendMessageStream.ts |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/components/message-entry-container/tools/paper-score.tsx |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/components/message-entry-container/tools/paper-score-comment/index.tsx |
Updated fromJson import to use the new wrapper |
webapp/_webapp/src/components/message-entry-container/tools/paper-score-comment/add-comments-button.tsx |
Updated fromJson import to use the new wrapper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export function fromJson<Desc extends DescMessage>( | ||
| schema: Desc, | ||
| json: JsonValue, | ||
| ): InstanceType<Desc["message"]> { | ||
| return bufFromJson(schema, json, { | ||
| ignoreUnknownFields: true, | ||
| }); |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper function doesn't support passing additional options that might be needed in the future. Consider adding an optional third parameter to allow callers to override or extend the default options while still preserving the ignoreUnknownFields: true default behavior. This would make the wrapper more flexible for future use cases where other JsonReadOptions might be needed (e.g., typeRegistry for custom types).
| /** | ||
| * Test file to demonstrate that the protobuf-utils wrapper handles unknown fields gracefully. | ||
| * | ||
| * This test can be run manually to verify the fix. Since the project doesn't have | ||
| * a test runner configured, this serves as documentation of the expected behavior. | ||
| * | ||
| * To test manually: | ||
| * 1. Add a new field to a protobuf schema on the backend | ||
| * 2. Deploy the backend | ||
| * 3. Use an older version of the webapp (without regenerating protobuf files) | ||
| * 4. Verify that the webapp doesn't crash when receiving the new field | ||
| */ | ||
|
|
||
| import { fromJson } from "./protobuf-utils"; | ||
| import { MessageSchema } from "../pkg/gen/apiclient/chat/v2/chat_pb"; | ||
|
|
||
| /** | ||
| * Example: Testing that fromJson ignores unknown fields | ||
| * | ||
| * This would simulate a backend returning a message with a new field | ||
| * that doesn't exist in the current schema. | ||
| */ | ||
| function testIgnoreUnknownFields() { | ||
| // Simulate JSON response from backend with an extra field "newField" | ||
| const jsonWithUnknownField = { | ||
| messageId: "test-123", | ||
| payload: { | ||
| user: { | ||
| content: "Hello", | ||
| selectedText: "", | ||
| newFieldThatDoesntExistYet: "This is a new field from a newer backend version", | ||
| }, | ||
| }, | ||
| timestamp: "0", | ||
| }; | ||
|
|
||
| try { | ||
| // This should NOT throw an error even though "newFieldThatDoesntExistYet" doesn't exist in the schema | ||
| const message = fromJson(MessageSchema, jsonWithUnknownField); | ||
| console.log("✓ Successfully parsed message with unknown field"); | ||
| console.log(" Message ID:", message.messageId); | ||
| console.log(" User content:", message.payload.user?.content); | ||
| return true; | ||
| } catch (error) { | ||
| console.error("✗ Failed to parse message with unknown field:", error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Example: Testing that fromJson still validates required fields | ||
| */ | ||
| function testRequiredFieldsStillValidated() { | ||
| // Missing required messageId field | ||
| const invalidJson = { | ||
| payload: { | ||
| user: { | ||
| content: "Hello", | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| try { | ||
| const message = fromJson(MessageSchema, invalidJson); | ||
| console.log("✓ Parsed message (messageId will be empty string):", message.messageId); | ||
| return true; | ||
| } catch (error) { | ||
| console.error("✗ Failed to parse message:", error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // Export test functions for manual testing | ||
| export { testIgnoreUnknownFields, testRequiredFieldsStillValidated }; |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test file contains only exported functions but no executable tests. Since the project doesn't have a test runner configured (no test scripts in package.json, no jest/vitest/mocha dependencies), this file serves as documentation rather than automated tests. Consider either: 1) setting up a test runner and converting these to actual test cases, or 2) renaming the file to something like protobuf-utils.examples.ts or moving the documentation to a comment/doc file to better reflect its current purpose as manual testing documentation.
The webapp crashes when the backend introduces new protobuf fields because
fromJsonstrictly validates against the schema.Changes
protobuf-utils.ts: WrapsfromJsonwithignoreUnknownFields: trueoptionfromJsonimports to use the new wrapperThis allows older webapp versions to work with newer backend versions that add fields, following standard protobuf forward compatibility patterns.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
buf.build/usr/local/bin/node node /usr/local/bin/npm install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Note
Ensures protobuf JSON parsing ignores unknown fields to avoid crashes when backend adds new fields.
libs/protobuf-utils.tswithfromJsonwrapper (ignoreUnknownFields: true)fromJsonfrom the new utility instead of@bufbuild/protobuflibs/protobuf-utils.test.tsdocumenting manual tests for forward compatibilityfromJsonfrom@bufbuild/protobuf)Written by Cursor Bugbot for commit a3862a6. This will update automatically on new commits. Configure here.